package com.swq.java.code.chapter18.code32;

import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.*;

public class ZipVisitor {
    public void readZip(String zipFile) throws Exception {
        FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), null);

        //遍历目录树
        Files.walkFileTree(fs.getPath("/"), new SimpleFileVisitor<Path>() {
            //在visitFile()方法中指定遍历每个文件时的具体操作
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                    throws IOException {
                System.out.println(file);
                return FileVisitResult.CONTINUE;
            }
        });
    }

    public static void main(String[] args) throws Exception {
        ZipVisitor visitor = new ZipVisitor();
        // 这里改成自己的JDK路径
        visitor.readZip("C:\\Program Files\\Java\\jdk1.8.0_181\\javafx-src.zip");
    }
}